home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0705.dms / q0705.adf / Amiga / Appendices / Examples / GraphicsExamples.doc < prev    next >
Text File  |  1992-07-29  |  16KB  |  428 lines

  1. 3    GRAPHICS
  2.  
  3. 3.1  LOW LEVEL GRAPHICS ROUTINES
  4.  
  5. Example1
  6.   This example shows how to create your own display, and fill
  7.   it with a lot of pixels in seven different colours.
  8.  
  9. Example2
  10.   This example shows how to create a large Raster and a smaller
  11.   display. We fill the Raster with a lot of pixels in seven
  12.   different colours and by altering the RxOffset and RyOffset
  13.   values in the RasInfo structure, the Raster is scrolled in
  14.   all directions. This method to scroll a large drawing in full
  15.   speed is used in many games and was even used in my own
  16.   racing game "Car".
  17.  
  18. Example3
  19.   This example shows how to create a display that covers the
  20.   entire display. This method is called "Overscan", and is
  21.   primarily used in video and graphics programs, but can also
  22.   be used in games etc to make the display more interesting.
  23.  
  24. Example4
  25.   This example demonstrates how to open two different ViewPorts
  26.   on the same display. The first ViewPort is in low resolution
  27.   and use 32 colours, while the second ViewPort is in high
  28.   resolution and only use 2 colours.
  29.  
  30. Example5
  31.   This example demonstrates how to open a ViewPort in interlace
  32.   mode.
  33.  
  34. Example6
  35.   This example demonstrates how to create a ViewPort in dual
  36.   playfield mode. Playfield 1 use four colours and is placed
  37.   behind playfield 2 which only use two colours (transparent
  38.   and grey). Playfield 1 is filled with a lot of dots and is
  39.   scrolled around while playfield 2 is is not moved and is
  40.   filled with only five grey rectangles.
  41.  
  42. Example7
  43.   This example demonstrates how to create a ViewPort with the
  44.   special display mode "Hold and Modify".
  45.  
  46. Example8
  47.   This example shows how to use the functions: SetAPen(),
  48.   SetBPen(), SetOPen(), SetDrMd(), SetDrPt(), WritePixel(),
  49.   ReadPixel(), Move(), Draw(), Text() and finally PolyDraw().
  50.  
  51. Example9
  52.   This example shows how to flood fill a figure, and how to
  53.   draw filled rectangles (both solid as well as filled with
  54.   single and multi coloured patterns).
  55.  
  56. Example10
  57.   This example demonstrate how to use the Area Fill functions.
  58.   [ AreaMove(), AreaDraw() and AreaEnd(). ]
  59.  
  60. Example11
  61.   This example demonstrate how to copy rectangular memory areas
  62.   with help of the blitter. 
  63.  
  64.  
  65.  
  66. 3.2  FONTS
  67.  
  68. Example 1
  69.   This example shows how to open the ROM font "Topaz". (Topaz
  70.   is the standard system font, and is placed in ROM on all
  71.   Amigas. If you have told preferences to use a 60-character
  72.   display the 9 pixel size will be used, else (80-character
  73.   display) the 8 pixel size will be used. This example prints
  74.   some text in both sizes.
  75.  
  76. Example 2
  77.   This example demonstrates how to change the style of a font.
  78.   We will open the ROM font "Topaz" and change the style to
  79.   underlined, bold and italic. Well, we try to use all
  80.   mentioned styles, but it may happen that we are not allowed
  81.   to use some styles.
  82.  
  83. Example 3
  84.   This example demonstrates how to open a disk font (Opal, 12)
  85.   and prints some characters with the new font in a window.
  86.   Note! The font "Opal" must exist in the systems FONT:
  87.   directory or you will receive an error message!
  88.  
  89. Example 4
  90.   This example opens disk fonts and prints some interesting
  91.   information about them. (Height, width, flags, style, etc...)
  92.   Syntax: Example4 [font1] [font2] [font3] ...
  93.   (The largest size of each font will be used.)
  94.  
  95. Example 5
  96.   This example demonstrates how to use the AvailFonts()
  97.   function. All available fonts (both on the disk as well as in
  98.   the memory) will be listed together with some useful
  99.   information about them.
  100.  
  101. Example 6
  102.   This example demonstrates how you can use a font loaded from
  103.   a disk in your own Intuition programs.
  104.  
  105.  
  106.  
  107. 3.3  SPRITES
  108.  
  109. Example1
  110.   This program shows how to declare and initialize some sprite
  111.   data and a SimpleSprite structure. It also shows how to
  112.   reserve a sprite (sprite 2), and how to move it around. The
  113.   user moves the sprite by pressing the arrow keys.
  114.  
  115. Example2
  116.   This program shows how to declare and initialize some sprite
  117.   data and a SimpleSprite structure. It also shows how to
  118.   reserve a sprite (sprite 2), and how to move it around. The
  119.   user moves the sprite by pressing the arrow keys. In this
  120.   example we animate the sprite (6 frames, taken from
  121.   the arcade game Miniblast).
  122.  
  123. Example3
  124.   This program shows how to set up a 15 coloured sprite, and
  125.   how to move it around.
  126.  
  127.  
  128.  
  129. 3.4  VSPRITES
  130.  
  131. Example1
  132.   This example demonstrates how to get and use a VSprite.
  133.   The VSprite can be moved around by the user by pressing
  134.   the arrow keys.
  135.  
  136. Example2
  137.   This example demonstrates how to use several VSprites each
  138.   with its own colour table.
  139.  
  140. Example3
  141.   This program demonstrates how to animate several (!) VSprites.
  142.  
  143. Example4
  144.   This example demonstrates how to use a VSpriteon a display
  145.   you have created yourself. We must now use the low level
  146.   functions MrgCop(), and LoadView(), instead of the more
  147.   sophisticated functions MakeScreen(), RethinkDisplay().
  148.  
  149.  
  150.  
  151. 3.5  BOBS
  152.  
  153. Example 1
  154.   This example demonstrates how to use a BOB. This BOB does
  155.   not have any features like saving the background, have
  156.   transparent parts etc. It is simply a BOB which can be
  157.   moved around the screen by pressing the arrow keys.
  158.  
  159.   Since this BOB will not restore the background, it will
  160.   leave a trace of lines after itself while it is moving.
  161.   As you will also notice, the BOB will not have any
  162.   transparent parts. If you move the BOB over some lines
  163.   there will appear to be a box around the BOB.
  164.  
  165. Example 2
  166.   This example demonstrates how to use a BOB that restores
  167.   the background as it is moving around on the display. This
  168.   time we use a high resolution screen, and the BOB will
  169.   therefore also be smaller than in the previous example.
  170.   Normal hardware sprites as well as VSprites are not
  171.   affected by the display modes, while BOBs are.
  172.  
  173. Example 3
  174.   This example demonstrates how to use a BOB that has
  175.   transparent areas. The BOB will also restore the
  176.   background while it is moving around. This BOB will
  177.   therefore act like a normal sprite, but can be much
  178.   larger, have more colours, and there is no limit on
  179.   how many BOBs can be used at the same time.
  180.  
  181. Example 4
  182.   This example demonstrates how to use a BOB on a display
  183.   which we have created ourself. This BOB will also use
  184.   three different images which we switch between to make
  185.   the missile really look like it is flying.
  186.  
  187. Example 5
  188.   This example demonstrates how to use several BOBs on a
  189.   single display. Note that the BOBs are some times
  190.   flashing and may appear to "flicker". The reason why
  191.   it looks like that is that the Amiga does not manage
  192.   to draw all BOBs before they are displayed. If you
  193.   only intend to use a small limited number of BOBs there
  194.   is usually not any problems. However, if you are using
  195.   many BOBs, as this example demonstrates, they may start
  196.   to "flicker". See next example on how to solve this
  197.   problem.
  198.  
  199. Example 6
  200.   This example demonstrates how to use a BOB on a double
  201.   buffered display. If you have to use several BOBS it
  202.   may happen that the user can see that the BOBs are
  203.   drawn, and they appear to "flicker". By using a double
  204.   buffered display we can draw the BOBs into one bitmap
  205.   while we are displaying the other. When all objects
  206.   have been drawn we switch bitmap and prepares the
  207.   other and so on...
  208.  
  209. Example 7
  210.   This example demonstrates how to use several BOBs on a
  211.   double buffered display. No matter how many BOBS we draw
  212.   they will never "flicker" as would happen if we used a
  213.   normal single display. Try and change the "BOB_NR" to 50
  214.   (or even higher) and watch your Amiga sweat!
  215.  
  216.   This example also demonstrates how you can use one single
  217.   image and yet draw the BOBs in several different colours.
  218.  
  219. Example 8
  220.   This example demonstrates how to use the automatic collision
  221.   routines. 15 BOBs will be randomly placed on the screen. The
  222.   BOBs will have the colours red, green and blue (set randomly).
  223.   The BOBs will then start to move in all directions. If a BOB
  224.   has hit the border of the display the collision routine will
  225.   detect this and change that BOB's direction. If a BOB hits
  226.   another BOB three things may happen:
  227.  
  228.   1. If one of the BOB was green and the other red both will
  229.      become yellow.
  230.  
  231.   2. If a blue BOB has hit a green or red BOB the green or red
  232.      BOB will become yellow, while the blue BOB is unchanged.
  233.  
  234.   3. If a yellow BOB hits another BOB nothing will happen. (No
  235.      collision events will be triggered.)
  236.  
  237. Example 9
  238.   In this example are we using a BOB as a planet rotating
  239.   around another BOB which is the sun. The planet consists
  240.   of 13 images all in different sizes. By moving the planet
  241.   from side to side and at the same time changing the size of
  242.   the image it looks like the planet is moving around the
  243.   sun. To make the impression realistic we have to place the
  244.   planet in front of the sun when the image of the planet is
  245.   large, and place it behind the sun when the image is small.
  246.   
  247.   This is a simple demonstration how you can use the "Before"
  248.   and "After" fields of the Bob structure. To add a "little
  249.   extra touch" to the program are we altering the colours of
  250.   the planet as it is moving around the sun.
  251.   
  252.   Since we are using quite a lot of graphics I have divided
  253.   this example into three parts. The main module is this file
  254.   "Example9.c". All graphics is placed in the second file
  255.   "Example9Graphics.c", and all constants are declared in the
  256.   third file "Example9.h" which is included by the two other
  257.   modules. Both this file and the graphics file are compiled
  258.   separately and then linked together.
  259.   
  260.   If you are using the SAS (Lattice) C Compiler you simply do
  261.   the following things: (If you do not have the SAS (Lattice)
  262.   C compiler you should check your own manual for more
  263.   information about how to link two modules together.)
  264.     1. Compile this module: "lc Example9.c"
  265.     2. Compile the graphic module: "lc Example9Graphics.c"
  266.     3. Link both files together: "blink with Example9.lnk"
  267.        (The file "Example9.lnk" contains all information the
  268.        linker needs to tie the two modules together.)
  269.  
  270.  
  271.  
  272. 3.6  GRAPHICAL TRICKS
  273.  
  274. Example 1
  275.   This example demonstrates how you can use the Blitter to
  276.   copy areas and do logical operations like "AND", "OR", and
  277.   "INVERT". These types of operations are necessary if you
  278.   want to place a picture on top of a background area, but
  279.   leave some areas unchanged.
  280.  
  281.   In this example we will copy a "source" picture on top of
  282.   a "background". Only the masked areas should be copied,
  283.   and the rest of the background should be left unchanged.
  284.   TO illustrate how the binary operations are executed we
  285.   are using two simple areas which should be combined, and we
  286.   are only using four colours.
  287.  
  288.     Source + Destination + Mask = Result
  289.     ------   -----------   ----   ------
  290.     0110     0123          0110   0113
  291.     0220     1230          0110   1220
  292.     3312     2301          1111   3312
  293.     1002     3012          1001   1012
  294.  
  295. Example 2
  296.   This example demonstrates what happens if you copy an
  297.   image on top of a background and do not use a mask. As
  298.   you will see, a complete copy of the image will replace
  299.   the background. Even the background colour (black) will
  300.   be copied.
  301.  
  302.   Sometimes you may want to place a picture on top of a
  303.   background, but do not want to copy everything. You may
  304.   for example only want to copy the image, but not the
  305.   background colour around it. To do this you have to use
  306.   a "mask" which tells the computer which pixels of the
  307.   background should be modified, and which should not.
  308.   Next example demonstrates this.
  309.  
  310. Example 3
  311.   This example demonstrates how you can draw an graphical
  312.   image on top of a background. The interesting thing about
  313.   this example is that we are using the Blitter to draw
  314.   the image together with a mask that makes some areas of
  315.   the image transparent.
  316.  
  317. Example 4
  318.   This example demonstrates how to use a double buffered
  319.   display. Although we draw a lot of lines the animation
  320.   is smooth and does not "flicker".
  321.  
  322. Example 5
  323.   This example demonstrates how you can use some small
  324.   graphical blocks ("map blocks") to compose a whole
  325.   display. With this technique can you create hundreds
  326.   of different maps, and still not use much memory.
  327.  
  328. Example 6
  329.   This example demonstrates how to scroll a large mountain.
  330.   The mountain is much wider than the screen. We can 
  331.   therefore only see a part of the mountain as we scroll it.
  332.  
  333.   Note that the mountain is sometimes "flashing"! The reason
  334.   why this happens is that we are scrolling the mountain at
  335.   the same time as we display it. If we are unlucky we have
  336.   only scrolled some of the BitPlanes when the mountain is
  337.   redrawn, and thus the wrong coulours are used. (When we
  338.   scroll a RastPort we actually move the BitPlanes
  339.   separately. If you are using a display with a lot of 
  340.   colours, BitPlanes, it may happen that we do not manage to
  341.   move all of them within one display frame.)
  342.  
  343.   To avoid this flickering we need to use a double buffered
  344.   display, where we show one of the screens as we scroll and
  345.   redraw the other. See next example.
  346.  
  347. Example 7
  348.   This example is very similar to the previous example,
  349.   but this time are we using a double buffered display.
  350.   The mountain will therefore not appear to flash like
  351.   it did before.
  352.   
  353. Example 8
  354.   This example demonstrates how you can write programs that
  355.   are scrolling huge maps. The maps are of course built with
  356.   help of several map blocks. We are also using a double
  357.   buffered display to avoid any flickering and create smooth
  358.   scrolling. (The scrolling is not perfectly smooth since
  359.   other tasks running at the same time are now and then
  360.   stealing the processor from our program. If you add more
  361.   things to the program like BOBs etc the scrolling will be
  362.   a bit slower but actually also smoother.)
  363.  
  364. Example 9
  365.   This example demonstrates how you can write a "Text Scroller".
  366.   It can use fonts of any size, and will automatically adjust
  367.   the size of the display. To make the scrolling smooth and nice
  368.   are we using a double buffered display.
  369.  
  370.   Synopsis: Example9 <fontname.font> <size> <textfile>
  371.   fontname: Name of the font you want to use. Eg: Coop.font
  372.   size:     Height of the font.               Eg: 42
  373.   textfile: File name of the text file. The characters in the
  374.             file will be printed.             Eg: Text.doc
  375.  
  376.   E.g.: Example9 Coop.font 42 Text.doc
  377.  
  378.  
  379.  
  380. 3.7  3D
  381.  
  382. Box3D
  383.   In this example we will rotate a 3D-rectangle. We will turn
  384.   it in all three dimensions (x, y and z) and use perspective
  385.   (the further away from the eye the smaller the object will
  386.   be).
  387.  
  388. Commodore3D
  389.   In this example we will rotate a more complex 3D-object. We
  390.   will turn it in all three dimensions (x, y, and z) and use
  391.   perspective.
  392.  
  393.  
  394.  
  395. 3.8  COPPER
  396.  
  397. Example 1
  398.   This example demonstrates how you can use your own copper
  399.   list. The copper list is connected to a screen running under
  400.   Intuition.
  401.  
  402. Example 2
  403.   This example demonstrates how you can use your own copper
  404.   list. The copper list is connected to a display which we have
  405.   made ourself.
  406.  
  407. Example 3
  408.   This example demonstrates how you can write a "Text Scroller"
  409.   which is both using a double buffered display to create
  410.   smooth scrolling and our own colour copper list.
  411.  
  412.   The font we are using is not loaded from the disk. We have 
  413.   instead included it in the program code itself with help of 
  414.   "IncludeFont". The copper lists in all these examples were
  415.   made by CopperDraw.
  416.  
  417.   This program is a nice example on how you can combine the
  418.   examples and utilities in this manual to create impressive 
  419.   programs, games and demos.
  420.  
  421.   To start the program you have to give it one argument, a file-
  422.   name to the text file which will be printed:
  423.  
  424.   Synopsis: Example3 <textfile>
  425.   
  426.  
  427.  
  428.